package com.open.ssm.mqtt.sub;

import com.open.ssm.common.utils.spring.SpringUtils;
import com.open.ssm.mqtt.MqttConfig;
import com.open.ssm.mqtt.MqttConstants;

/** 
 * Title:Server MQTT消息的订阅端
 * 1：主动订阅 物联接入平台 发送的业务数据主题
 * 
 * Description:使用一个客户端链接 同时订阅的主题组
 * /v1/devices/{deviceId}/command  Link平台命令下发
 * 
 */
public class SubTopicFromCmdRes extends SubFromMqtt {
	
    //////单例模式///
    private static SubTopicFromCmdRes pubInstance = null;
    
    //mqtt的参数配置
  	private MqttConfig mqttConfig = SpringUtils.getBean(MqttConfig.class);
  	
	private SubTopicFromCmdRes() {
		initConnectOptions();
	}
	public static SubTopicFromCmdRes getInstance() {
	   if (pubInstance == null) {
		   pubInstance = new SubTopicFromCmdRes();
	   }
	   return pubInstance;
	}
	
	/**
	 * 初始化MqttConnectOptions
	 */
	private void initConnectOptions() {
		this.clientId = MqttConstants.SUB_DEVICE_COMMAND;
		//本地订阅-订阅者主题数组
    	this.topicList.clear();
    	this.topicList.add(MqttConstants.TOPIC_DEVICES_COMMANDRES);
		this.serverURI = mqttConfig.getServerURI();
		this.username = mqttConfig.getUsername();
		this.password = mqttConfig.getPassword();
		this.connectionTimeout = mqttConfig.getConnectionTimeout();
		this.keepAliveInterval = mqttConfig.getKeepAliveInterval();
		
		// 订阅回调
		this.mqttCallback = new SubTopicFromCmdResCallback();
	}
}  

